<template>
  <a-modal
    v-model="visible"
    :width="1000"
    :bodyStyle="bodyStyle"
    :footer="null"
    destroyOnClose
    @ok="handleOk"
  >
    <a-tabs @change="callback" v-if="codes" tabPosition="left">
      <a-tab-pane :tab="key.substring(key.lastIndexOf('/')+1,key.indexOf('.vm'))" v-for="(value, key) in codes" :key="key"><pre>{{ value }}</pre></a-tab-pane>
    </a-tabs>
  </a-modal>
</template>
<script>
import { previewTable } from '@/api/tool/gen'
export default {
  data () {
    return {
      visible: false,
      codes: null,
      bodyStyle: {
        height: '700px',
        overflowY: 'scroll'
      }
    }
  },
  methods: {
    show (tableId) {
      previewTable(tableId).then(res => {
        this.codes = res.data
      })
      this.visible = true
    },
    handleOk (e) {
      this.visible = false
    },
    callback (key) {
      console.log(key)
    }
  }
}
</script>
